package com.wh.synchronize;

public class SynchronizedTest implements Runnable {


	@Override
	public void run() {
		synchronized(this) {
	        for (int i = 0; i < 5; i++) {  
	        	try {
					Thread.currentThread().sleep(500);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
                System.out.println(Thread.currentThread().getName() + " synchronized loop " + i);  
           } 
		}
	}
	
	public static void main(String[] args) {
		Thread A = new Thread(new SynchronizedTest(), "A");
		Thread B = new Thread(A, "B");
		Thread C = new Thread(A, "C");
		
		A.start();
		B.start();
		C.start();
	}
}
